define(function(require, exports, module) {
  var tool = require("tool");
  var chaxun = require("chaxun");
  var log = require("log");
  var shengci = require("shengci");
  var inject = require("inject");
  var iframe = require("iframe");
  
  function linkClick(){
    $(this).css("color","blue");
    if(typeof($(this).attr("data-rel"))!='undefined'){
      //交给jauery mobile处理
      return;
    }
    tool.changePage($(this));
    return false;
  }
  
  function onclick(){
    var word = $(this).addClass("clicked").html().toLowerCase(); 
    shengci.update(word);  
    chaxun.cha(word);
    return false;
  }
  
  exports.init = function(rooturl) {
    
    tool.rooturl = rooturl;    
    $("a").live('click',linkClick);
    $('.word').live("click",onclick);
    $.get(rooturl+'main.html',function(result){
      $("body").html(result);
      log("main init");
      var root = location.href.replace("index.html","");
      require.async(
        tool.isChrome?[root+"jm/jquery.mobile-1.1.1.css",root+"jm/jquery.mobile-1.1.1.js","main.css"]:
                      [root+"jm/jquery.mobile-1.1.1.min.css",root+"jm/jquery.mobile-1.1.1.min.js","main.css"]
        ,function() {
          $.mobile.defaultDialogTransition = "none";
          $("#main").show();
          
          inject.set("");
          chaxun.init();
          iframe.init();
          shengci.show($("#shengcilist"));
        }
      );
    });    
  };
});